package com.googlecode.mgwt.examples.uibinder.client.activities;

import com.google.gwt.event.shared.EventBus;
import com.google.gwt.user.client.ui.AcceptsOneWidget;
import com.googlecode.mgwt.examples.uibinder.client.ClientFactory;
import com.googlecode.mgwt.examples.uibinder.client.activities.ExampleSourceDisplay.Presenter;
import com.googlecode.mgwt.examples.uibinder.client.places.ExamplePlace;
import com.googlecode.mgwt.examples.uibinder.client.places.ExamplePlace.ID;
import com.googlecode.mgwt.mvp.client.MGWTAbstractActivity;

public class ExampleSourceActivity extends MGWTAbstractActivity implements Presenter {

	private final ClientFactory clientFactory;
	private final ID id;
	private ExampleSourceDisplay display;

	public ExampleSourceActivity(ClientFactory clientFactory, ID id) {
		this.clientFactory = clientFactory;
		this.id = id;

	}

	@Override
	public void start(AcceptsOneWidget panel, EventBus eventBus) {
		display = clientFactory.getExampleSourceDisplay();

		String source = clientFactory.getSource(id);

		display.setPresenter(this);
		display.setSource(source);

		panel.setWidget(display);

	}

	@Override
	public void onStop() {
		display.setPresenter(null);
	}

	@Override
	public void onBackButtonPressed() {
		clientFactory.getPlaceController().goTo(new ExamplePlace(id));

	}

}
